﻿using System;
using System.Collections.Generic;
using STeaL.Functional;

namespace STeaL.Algorithm {

  public static partial class IListExtensions {
#region count_if
    public static int count_if<T>(this IList<T> list, int first, int last, Func<T,bool> pred) {
      int result = 0;
      for ( ; first != last; ++first ) {
        if ( pred(list[first]) ) ++result;
      }
      return result;
    }

    public static int count_if<T>(this IList<T> list, Func<T,bool> pred) {
      return count_if(list, 0, list.Count, pred);
    }

#endregion
#region count
    public static int count<T>(this IList<T> list, int first, int last, T val) where T : IComparable<T> {
      return count_if(list, first, last, (x) => x.CompareTo(val) == 0);
    }

    public static int count<T>(this IList<T> list, T val) where T : IComparable<T> {
      return count_if(list, 0, list.Count, (x) => x.CompareTo(val) == 0);
    }

#endregion
  }
}
